﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Management;

namespace FAST
{
    class Helper
    {

        /// <summary>
        /// This method computes the md5 hash code of a file given its full file path.
        /// </summary>
        /// <param name="f">The full file path</param>
        /// <returns>Return string of string builder</returns>
        /// <exception cref="UnauthorizedAccessException">If the user is not allowed to access the drive.</exception>
        public string computeHashCode(string f)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            StringBuilder sb = new StringBuilder();

            try
            {
                using (FileStream fs = File.Open(f, FileMode.Open))
                {
                    foreach (byte b in md5.ComputeHash(fs))
                        sb.Append(b.ToString("x2").ToLower());
                }
            }
            catch
            {
            }
            return sb.ToString();
        }


        /*
        /// <summary>
        /// Gets the external drive id.
        /// </summary>
        /// <param name="drive">The letter of the drive</param>
        /// <returns>Returns the unique Volume ID of the external drive as a string, given the drive alphabet e.g. "D"</returns>
        public string getExternalDriveID(string drive)
        {
            ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
            dsk.Get();
            string volumeSerial = dsk["VolumeSerialNumber"].ToString();
            //Console.WriteLine("volume serial: " + volumeSerial);
            return volumeSerial;
        }
        */

    }
}
